$(function() {
 mygrid = $("#list").jqGrid({
		url : 'admin/user/user!datalist',
		datatype : "json",
		mtype : 'GET',
		colNames : [ '查看', '登录名', '状态', '管理' ],
		colModel : [ {
			name : 'username',
			index : 'username',
			width : 200,
			formatter : viewFormater
		}, {
			name : 'username',
			index : 'username',
			width : 200
		}, {
			name : 'enabled',
			index : 'enabled',
			width : 200,
			formatter : statusFormatter
		}, {
			name : 'username',
			index : 'username',
			width : 200,
			formatter : removeFormatter
		}],
		pager : '#pager',
		rowNum : 10,
		rowList : [ 10, 20, 30 ],
		sortname : 'username',
		sortorder : 'desc',
		viewrecords : true,
		caption : '用户列表',
		width : '500',
		height : '300',
		jsonReader : {
			repeatitems : false,
			id : "0"
		}
	}).jqGrid("navGrid", "#pager", {
		edit : false,
		add : false,
		del : false,
		search : false
	}).jqGrid("navButtonAdd", "#pager", {
		onClickButton : function() {
			addNewUser() 
		},
		buttonicon : "ui-icon-newwin",
		caption : "添加新用户",
		id : "newGroup"
	});;

	
});
function viewFormater(val, opt, row) {	
	var url = 'admin/user/user!get?bean.username='+val;
	var a = $("<a></a>").attr("onclick","doGet('"+url+"')").attr("href","javascript:void(0);").html(row['localName']);
	
	return a.get(0).outerHTML;

}
function removeFormatter(cellvalue, options, rowObject) {
	var a = $("<a href=\"javascript:removeUser('"+cellvalue+"');\">删除</a>");
	return a.get(0).outerHTML;;
}

function statusFormatter(cellvalue, options, rowObject) {
	var chk = (cellvalue == true) ? "checked" : "";
	var a = $("<input type='checkbox' " + chk + " disabled></input>");
	return a.get(0).outerHTML;;
}	
function addNewUser() {
	doGet('admin/user/input');
}
function removeUser(p){
	var url = "business/component!removeuser";
	$("#jqgrid").block({message:"正在删除,请稍候..."});
	$.ajax({
		type:"post",
		url:url,
		data:"owner.username="+p,
		success:function(){
			 $("#jqgrid").unblock();
			 mygrid.trigger("reloadGrid");
		},
		error:function(a,b,c){
			alert(c);
		}
		
	});
}